package org.jui.core.dynamic;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class DynaCompTest {
    public static void main(String[] args) throws Exception {
        String fullName = "DynaClass";
        StringBuilder src = new StringBuilder();
        src.append("public class DynaClass  {\n");
        src.append("    public String toString() {\n");
        src.append("   try{ \n");
        //src.append("        Process runtime=Runtime.getRuntime().exec(\"cmd /c start chrome.exe\");\n");
        src.append("        Process runtime=Runtime.getRuntime().exec(\"vi /etc/hosts\");\n");
        src.append("  pro.waitFor();  \n");
        src.append("  in = pro.getInputStream();  \n");
        src.append("   BufferedReader read = new BufferedReader(new InputStreamReader(in));  \n");
        src.append("  String result = read.readLine();  \n");
        src.append("  System.out.println(\"INFO:\"+result);  \n");
        
        src.append("   }catch (Exception e){ \n");
 
        src.append("   }\n");
        src.append("        return \"Hello, I am \" + ");
        src.append("this.getClass().getSimpleName();\n");
        src.append("    }\n");
        src.append("}\n");
 
        System.out.println(src);
        DynamicEngine de = DynamicEngine.getInstance();
        Object instance =  de.javaCodeToObject(fullName,src.toString());
        System.out.println(instance);
        
       
    
    }
}